/*
*每日秒杀
 */
import React from 'react'
import $ from  'jquery'
import './SeckillArea.css'
import  Swiper_3 from '../../../../components/Swiper_3/Swiper_3'
let r_day='';
let r_hour='';
let r_minute='';
let r_second='';
class SeckillArea extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            SeckillArea:1,
            siwper_3_data:[],
            time_out:'',
            r_day:'',
            r_hour:'',
            r_minute:'',
            r_second:''
        };
    }
    componentWillReceiveProps(nextProps){
        if(nextProps.SeckillArea.children2){
            this.setState({
                siwper_3_data: nextProps.SeckillArea.children2,
                income_time_out:nextProps.SeckillArea.remaining_time
            });
           // this.timeout(nextProps.SeckillArea.remaining_time,this)
            this.time_out(nextProps.SeckillArea.remaining_time,this)
        }
    }

     timeout(obj,ow){
        let  _this=ow
        let _timeCha =obj;
        let _day = Math.floor(_timeCha / (3600 * 24));
        let _day2 = _timeCha / (3600 * 24);
        let _hour2 = (_timeCha - (_day * 3600 * 24)) / 3600;
        let _hour = Math.floor(_hour2)
        let _miunte2 = (_timeCha - (_hour * 3600) - (_day * 3600 * 24)) / 60
        let _minute = Math.floor(_miunte2)
        let _second2 = _timeCha - (_day * 3600 * 24) - (_hour * 3600) - (_minute * 60);
        let _second = Math.floor(_second2)
         this.setState({
            r_day: _day,
            r_hour:_hour,
            r_minute:_minute,
            r_second:_second
         });
         let _litime;

         if (obj> 0) {
             _litime = setInterval(function() {
                 _timeRun()
             }, 1000);
         }

         function _timeRun() {
             var se=--_this.state.r_second;
             $('.r_second').html(123456);
             _this.setState({
                 r_second: --_this.state.r_second,
             });

             if (_this.state.r_second < 0) {
                 _this.setState({
                     r_minute: --_this.state.r_minute,
                     r_second:59
                 });
             }
             if (_this.state.r_minute < 0) {
                 _this.setState({
                     r_hour: --_this.state.r_hour,
                     r_minute:59
                 });
             }
             if (_this.state.r_hour < 0) {
                 _this.setState({
                     r_day: --_this.state.r_day,
                     r_hour:23
                 });
             }
             if (_this.state.r_day < 0) {
                 _this.setState({
                     r_day: 0,
                     r_hour:0,
                     r_minute : 0,
                     r_second : 0,
                 });
                clearInterval(_litime)
             }
         }
     }
     time_out(ti){
         console.log(Date.parse(new Date()));
         var timeCha = ti;
         var day = Math.floor(timeCha / (3600 * 24));
         var day2 = timeCha / (3600 * 24);
         var hour2 = (timeCha - (day * 3600 * 24)) / 3600;
         console.log(hour2)
         var hour = Math.floor(hour2)
         var miunte2 = (timeCha - (hour * 3600) - (day * 3600 * 24)) / 60
         var minute = Math.floor(miunte2)
         var second2 = timeCha - (day * 3600 * 24) - (hour * 3600) - (minute * 60);
         var second = Math.floor(second2)
         r_day = day;
         r_hour = hour;
         r_minute = minute;
         r_second = second;
         $('.r_day').text(r_day)
         $('.r_hour').text(r_hour)
         $('.r_minute').text(r_minute)
         $('.r_second').text(r_second)
         var litime;
         if (ti > 0) {
             litime = setInterval(function() {
                 timeRun()
             }, 1000);
         }

         function timeRun() {

             --r_second;
             $('.r_second').text(r_second)
             if (r_second < 0) {
                 --r_minute;
                 $('.r_minute').text(r_minute)
                 r_second = 59;
                 $('.r_second').text(59)
             }
             if (r_minute < 0) {
                 --r_hour;
                 $('.r_hour').text(r_hour)
                 r_minute = 59;
                 $('.r_minute').text(59)
             }
             if (r_hour < 0) {
                 --r_day;
                 $('.r_day').text(r_day)
                 r_hour = 23
                 $('.r_hour').text(23)
             }
             if (r_day < 0) {
                 r_day = 0;
                 r_hour = 0;
                 r_minute = 0;
                 r_second = 0;
                 $('.r_day').text(r_day)
                 $('.r_hour').text(r_hour)
                 $('.r_minute').text(r_minute)
                 $('.r_second').text(r_second)
                 clearInterval(litime)
             }
         }
     }
    render() {

        return (
            <div className="SeckillArea_content">
                <div className="SeckillArea_title">
                    <div style={{fontSize:'16px'}}>每日秒杀</div>
                    <div
                     style={{fontSize:'14px'}}
                    >
                         下次更新:10:00
                         {/*<span className="r_hour"></span>:<span className="r_minute"></span>:<span className="r_second"></span>*/}
                    </div>
                    <div
                        style={{fontSize:'14px'}}
                    >工作日10点更新</div>
                </div>
                <Swiper_3  swiper_3_data={this.state.siwper_3_data}  swipeSpeed="20" speed="800" />
            </div>
        )
    }
}


export default SeckillArea